<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <link rel="stylesheet" href="${staticServer}/inc/style/main.css"/>
    <link rel="stylesheet" href="${staticServer}/inc/style/page.css"/>
    <link rel="stylesheet" href="${staticServer}/css/struct_info.css"/>
    <script src="${staticServer}/inc/js/jquery.js"></script>
    <script src="${staticServer}/inc/js/pageset.js"></script>
    <script src="${staticServer}/inc/js/submitter.js"></script>
    <script src="${staticServer}/inc/js/infopad.js?2.2"></script>
    <script type="text/javascript" src="${staticServer}/common/uploadify/jquery.uploadify.js"></script>
    <script type="text/javascript" src="${staticServer}/js/web/uploadImg.js?1.5"></script>

    <link rel="stylesheet" href="${staticServer}/inc/style/date/datepicker.css"/>
    <script src="${staticServer}/inc/js/datepicker.js"></script>

    <style>
        #SWFUpload_0 {
            margin-top: 70px;
            margin-left: -30px;
        }
    </style>
    <script>
        var contextPath = '${contextPath}';
        var _contextPath = '${staticServer}';

        $(function () {
            $("#type").val("<#if goods??>${goods.type}</#if>");
            $("#center_id").val("<#if goods??>${goods.center_id}</#if>");
            $("#purpose").val("<#if goods??>${goods.purpose}</#if>");
            $("#state").val("<#if goods??>${goods.state}</#if>");

        });


    </script>

    <script>
        function addGood() {
            var center_name = $("#center_id option:selected").text();		//中心名字
            var region = $("#center_id option:selected").val();		//中心
            var good_name_id = $("#good_name_id option:selected").val();	//物品分类
            var itemName = $("#itemName option:selected").text();			//物品名称
            var itemId = $("#itemName option:selected").val();		//中心
            var number = $("#number").val();								//物品数量
            var msg = $("#msg").val();										//备注*/
            if (center_name == "") {
                infopad.err("请选择中心!");
                return;
            }
            if (itemName == "") {
                infopad.err("请选择物品名称!");
                return;
            }
            if (good_name_id == "") {
                infopad.err("请选择物品名称!");
                return;
            }
            if (number == "") {
                infopad.err("请输入数量!");
                return;
            }


            /*   $.post("${contextPath}
            /goods/addWarehouseGoods.htm", {
                            "good_name_id":good_name_id,
                            "center_name":center_name,
                            "itemName":itemName,
                            "number":number,
                            "msg":msg,
                            "region":region,
                            "itemId":itemId,
                        }, function(ms) {
                            var msg = ms.msg;
                            if(msg!=null && msg=="1"){
                                infopad.msg("操作成功！");
                                window.location.href="${contextPath}
            /goods/goodsList.htm";
                            }else{
                                infopad.err("操作失败，请联系管理员！");
                            }

                        });*/

            $.ajax({
                type: 'POST',
                url: 'addWarehouseGoods.htm',
                data: {
                    "good_name_id": good_name_id,
                    "center_name": center_name,
                    "itemName": itemName,
                    "number": number,
                    "msg": msg,
                    "region": region,
                    "itemId": itemId
                },
                dataType: "text",
                success: function (data) {
                    if (data != null && data == "true") {
                        alert("操作成功!");
                        window.location.href = "${contextPath}/goods/myGoodsList.htm";
                    } else {
                        alert("操作失败!");
                    }
                },
                error: function () {
                    alert("系统出现问题");
                }
            });

        }


    </script>


    <script language="JavaScript" type="text/javascript">
        function clearNoNum(obj) {
            obj.value = obj.value.replace(/[^\d.]/g, "");  //清除“数字”和“.”以外的字符
            obj.value = obj.value.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的
            obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
            obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3');//只能输入两个小数
            if (obj.value.indexOf(".") < 0 && obj.value != "") {//以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额
                obj.value = parseFloat(obj.value);
            }
        }
    </script>

    <script>
        function selectGoodName() {
            var good_name_id = $("#good_name_id option:selected").val();	//物品分类
            $.ajax({
                type: 'POST',
                url: 'ajaxSelectGoodName.htm',
                data: {"good_name_id": good_name_id},
                dataType: "json",
                success: function (data) {
                    if (data != null) {
                        $("#itemName").empty();
                        $.each(data, function (index, content) {
                            if (content.item_name != null && content.item_name != "") {
                                $("#itemName").append($("<option/>").text(content.item_name).attr("value", content.id));
                            }
                        });
                    } else {
                        alert("操作失败!");
                    }
                },
                error: function () {
                    alert("系统出现问题");
                }
            });


        }


    </script>

</head>
<input type="hidden" id="id" value="<#if goods??>${goods.id}</#if>">
<body>
<div id="home_link">
    <ul>
        <li></li>
        <li>&gt;</li>
        <li>采购管理</li>
        <li>&gt;</li>
        <li class="current">物品申请</li>
    </ul>
</div>

<div id="container">
    <div id="title">物品申请</div>
    <table id="infotable">
        <tr>
            <th>办公地址:</th>
            <td>
                <select id="center_id">
                <#if offList??>
                    <#list offList as list>
                        <option value="${list.keyname}">${list.name}</option>
                    </#list>
                </#if>
                </select>
            </td>
        </tr>

        <tr>
            <th>物品分类:</th>
            <td>
                <select id="good_name_id" onchange="selectGoodName()">
                <#if goodNamelist??>
                    <#list goodNamelist as list>
                        <option value="${list.id}">${list.name}</option>
                    </#list>
                </#if>
                </select>
            </td>
        </tr>
        <tr>
            <th>物品名称:</th>
            <td>
                <select id="itemName" onchange="">
                </select>

        </tr>
        <tr>
            <th>物品数量:</th>
            <td><input id="number" value="1" onchange="totalCalculation()"
                       onkeyup="this.value=this.value.replace(/[^0-9]/g,'')"
                       onafterpaste="this.value=this.value.replace(/[^0-9]/g,'')" type="text" size="50" maxlength="30"/>
            </td>
        </tr>
        <tr>
            <th>备注:</th>
            <td>
                <textarea id="msg" style="width:400px;height: 150px;"></textarea>

            </td>
        </tr>

    </table>
    <div id="controlbar">
        <input type="button" class="submit" onclick="addGood()" value="  保  存  "/>
    </div>
</div>

</body>
</html>